package Factory;

interface AbstractFactory {
    AbstractProductA createProductA(int p);
    AbstractProductB createProductB(int p);
}

class Factory1 implements AbstractFactory{
    @Override
    public AbstractProductA createProductA(int p) {
        return new ProductA1(p);
    }

    @Override
    public AbstractProductB createProductB(int p) {
        return new ProductB1(p);
    }
}

class Factory2 implements  AbstractFactory{
    @Override
    public AbstractProductA createProductA(int p) {
        return new ProductA2(p);
    }

    @Override
    public AbstractProductB createProductB(int p) {
        return new ProductB2(p);
    }
}

interface  AbstractProductA{
    String type = "A";
    void info();
}

interface  AbstractProductB{
    String type = "B";
    void info();
}

class ProductA1 implements AbstractProductA{
    @Override
    public void info() {
        System.out.println("ProductSerial:" + this.type + " " + this.serial);
    }
    public ProductA1(int p){
        this.serial = p;
        info();
    }
    private int serial;
}

class ProductA2 implements AbstractProductA{
    @Override
    public void info() {
        System.out.println("ProductSerial:" + this.type + " " + this.serial);
    }
    public ProductA2(int p){
        this.serial = p;
        info();
    }
    private int serial;
}

class ProductB1 implements AbstractProductB{
    @Override
    public void info() {
        System.out.println("ProductSerial:" + this.type + " " + this.serial);
    }
    public ProductB1(int p){
        this.serial = p;
        info();
    }
    private int serial;
}

class ProductB2 implements AbstractProductB{
    @Override
    public void info() {
        System.out.println("ProductSerial:" + this.type + " " + this.serial);
    }
    public ProductB2(int p){
        this.serial = p;
        info();
    }
    private int serial;
}

public class TestAbstractFactory{
    public static void main(String[] args){
        AbstractFactory factory = createFactory(1);
        if(null == factory)
            return;
        factory.createProductA(111);
        factory.createProductB(222);
        factory = createFactory(2);
        if(null == factory)
            return;
        factory.createProductA(333);
        factory.createProductB(444);
    }
    public static AbstractFactory createFactory(Integer type){
        if(type.equals(1)){
            return new Factory1();
        }
        else if(type.equals(2)){
            return new Factory2();
        }
        return null;
    }
}